/**
 * Copyright 2011 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.api.adwords.starterkit.settings;

import com.google.api.adwords.starterkit.db.structures.AdGroupStructure;
import com.google.api.adwords.v201101.cm.AdGroupStatus;

/**
 * The Class AdGroupSettings keeps all settings related to AdGroups.
 * 
 * @author rodrigo.f.vale@gmail.com (Rodrigo Vale)
 */
public class AdGroupSettings {
  private boolean autoPause;
  private long defaultCpc;
  private long defaultCpm;
  private long defaultCpa;
  private AdGroupStatus defaultStatus;
  private boolean isStatusModifiable;
  private boolean isBidModifiable;
  private boolean autoCreation;

  /**
   * Instantiates a new ad group settings.
   * 
   * @param autoPause the auto pause flag
   * @param defaultCpc the default cpc
   * @param defaultCpm the default cpm
   * @param defaultCpa the default cpa
   * @param defaultStatus the default status
   * @param syncStatus the sync status
   * @param syncBid the sync bid
   * @param autoCreation flag that allows starterkit to create new adGroups
   */
  public AdGroupSettings(boolean autoPause, long defaultCpc, long defaultCpm,
      long defaultCpa, AdGroupStatus defaultStatus, boolean syncStatus,
      boolean syncBid, boolean autoCreation) {
    setAutoPause(autoPause);
    setCpc(defaultCpc);
    setCpm(defaultCpm);
    setCpa(defaultCpa);
    setStatus(defaultStatus);
    setBidModifiable(syncBid);
    setStatusModifiable(syncStatus);
    setAutoCreation(autoCreation);
  }
  
  public AdGroupSettings() {
    setAutoPause(false);
    setCpc(0);
    setCpm(0);
    setCpa(0);
    setStatus(AdGroupStatus.ENABLED);
    setBidModifiable(true);
    setStatusModifiable(true);
    setAutoCreation(true);
  }

  /**
   * Sets the can modify bid flag. If set to false, StarterKit will not
   * modify the bid of an AdGroup even when direct requested by application.
   * See the canModifyXXXFlags at the manual for a deep dive explanation. 
   */
  public void setBidModifiable(boolean syncBid) {
    this.isBidModifiable = syncBid;
  }

  /**
   * Sets the can modify status flag. If set to false, StarterKit will not
   * modify the status of an AdGroup even when direct requested by application.
   * See the canModifyXXXFlags at the manual for a deep dive explanation. 
   */
  public void setStatusModifiable(boolean syncStatus) {
    this.isStatusModifiable = syncStatus;
  }

  public boolean isStatusModifiable() {
    return isStatusModifiable;
  }

  public boolean isBidModifiable() {
    return isBidModifiable;
  }

  public void setStatus(AdGroupStatus status) {
    this.defaultStatus = status;
  }

  public void setStatus(String status) {
    status = status.toUpperCase();
    AdGroupStructure.validateStatus(status);
    this.defaultStatus = AdGroupStatus.fromString(status);
  }

  public void setCpc(long cpc) {
    this.defaultCpc = cpc;
  }

  /**
   * sets the auto pause AdGroup flag. This flag controls if Starter Kit can
   * pause AdGroups automatically. An AdGroup is paused automatically when it
   * is present at the AdWords system, but the application do not mention it. 
   * See the demos for a better understanding of it or the AutoPause session at 
   * the manual.
   */
  public void setAutoPause(boolean autoPause) {
    this.autoPause = autoPause;
  }

  public AdGroupStatus getStatus() {
    return defaultStatus;
  }

  public Long getCpc() {
    return this.defaultCpc;
  }

  public boolean getAutoPause() {
    return this.autoPause;
  }

  public void setCpm(long adGroupDefaultCpm) {
    this.defaultCpm = adGroupDefaultCpm;
  }

  public long getCpm() {
    return defaultCpm;
  }

  public void setCpa(long defaultCpa) {
    this.defaultCpa = defaultCpa;
  }

  public long getCpa() {
    return defaultCpa;
  }

  /**
   * Sets the auto creation AdGroup flag. This flag controls if Starter Kit 
   * can create new AdGroup. Set to false to make sure that
   * the framework will not create any new AdGroup even if requested by
   * the application.
   */
  public void setAutoCreation(boolean autoCreation) {
    this.autoCreation = autoCreation;
  }

  public boolean getAutoCreation() {
    return autoCreation;
  }
}